<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="stylesheet_1.css">
        <title>Edit User</title>
        <style>
            span.error {
                color: red;
            }
        </style>
    </head>
    <body>

        <p align="right">
            Admin ${lastname} <c:url value="/j_spring_security_logout" var="logoutUrl" />
            (<a href="${logoutUrl}">Logout</a>)
        </p>

        <c:if test="${error != null}">
            <div style="color:#FF0000" align="center">
                <c:out value="${error}"/><br/><br/>
            </div>
        </c:if>

        <h1>Edit user</h1>

        <form:form method="POST" action="adminModifyUser.html"  modelAttribute="userForm" >
            <input type="hidden" name="id" value="${user.id}">
            <table width="70%" border="0" cellspacing="0" cellpadding="3">
                <tr>
                    <td>Login: </td>
                    <td><form:input path="login" type="text" value="${user.login}" readonly="true" /> <font color="red">*</font></td>
                    <td><span class="error"><form:errors path="login" /></span></td>
                </tr>
                <tr>
                    <td>Password: </td>
                    <td><form:input path="password" type="password" value="${user.password}"/> <font color="red">*</font></td>
                    <td><span class="error"><form:errors path="password" /></span></td>
                </tr>
                <tr>
                    <td>Password: </td> 
                    <td><form:input path="passwordConfirm" type="password" value="${user.password}"/> <font color="red">*</font></td>
                    <td><span class="error"><form:errors path="passwordConfirm" /></span></td>
                </tr>
                <tr>
                    <td>Email: </td> 
                    <td><form:input path="email" type="text" value="${user.email} "/> <font color="red">*</font></td>
                    <td><span class="error"><form:errors path="email" /></span></td>
                </tr>
                <tr>
                    <td>First name: </td> 
                    <td><form:input path="firstName" type="text" value="${user.firstName}"/> <font color="red">*</font></td>
                    <td><span class="error"><form:errors path="firstName" /></span></td>
                </tr>
                <tr>
                    <td>Last name: </td> 
                    <td><form:input path="lastName" type="text" value="${user.lastName}"/> <font color="red">*</font></td>
                    <td><span class="error"><form:errors path="lastName" /></span></td>
                </tr>
                <tr>
                    <td>Birthday: </td> 
                    <td><form:input path="birthday" type="text" value="${user.birthday}"/> <font color="red">*</font></td> 
                    <td><span class="error"><form:errors path="birthday" /></span></td>
                </tr>
                <tr>
                    <td>Role:</td>
                    <td><form:select path="role">
                            <c:set var="role" scope="request" value="${user.role.name}" />
                            <c:set var="roleUser" scope="request" value="ROLE_USER" />
                            <c:set var="roleAdmin" scope="request" value="ROLE_ADMIN" />
                            <form:option value="${role}"/>

                            <c:if test="${role == roleUser}">
                                <form:option value="ROLE_ADMIN"/>
                            </c:if>
                            <c:if test="${role == roleAdmin}">
                                <form:option value="ROLE_USER"/>
                            </c:if>
                        </form:select> <font color="red">*</font></td>
                </tr>
                <tr>
                    <td><input type="submit" value="OK"></td>
                    <td><input  type="button" value="Cancel" onclick="javascript:history.back();" /></td>
                <tr/>
            </table>
        </form:form>
    </body>
</html>